<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

class ApiController extends Controller
{
    //解析视频地址
    public function index(Request $request)
    {

//    let host = window.location.host
//    let string = 'mojo' + Math.round(time/3600) + host
//    let salt = bcrypt.genSaltSync(10);
//    let fuck = bcrypt.hashSync(string, salt);
//        $token = $request->get('token');
//        $allow_host = ['window.location.host',];
//        $hostname = gethostname();
//
//        $flag = in_array($hostname,$allow_host);
//        $time = round(time()/3600);
//        $stringgg = "mojo{$time}{$allow_host[0]}";
//        $flag = password_verify($stringgg,$token);
        //服务器需要安装you-get
        //python3.6
        $key = $request->input('url');
        $value = Cache::remember($key, 60, function () use ($key, $request) {
            //这个地方设计到很多权限
            ini_set('max_execution_time', '6');

            //字符串转换的问题
            $youGet = '/home/you-get/you-get';//centos 使用这个配置  到服务器上这个目录git pull 或者最新的 you-get
            //$youGet = 'you-get';//mac上使用这个配置

            $cmd = "export LANG=en_US.UTF-8; $youGet --json $key";
            exec($cmd, $ret);
            //dd(implode('',$ret));
            $content = implode('', $ret);
            $search = 'ups_client_netip=115.28.94.157';
            //$rep = 'ups_client_netip='.$request->getClientIp();

            //$content = str_ireplace($search,$rep,$content);
            $array = json_decode($content);
            return $array;
        });
        header("Access-Control-Allow-Origin: *");

        return response()->json($value);
    }


}
